package com.fau.cm.action.index;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fau.cm.action.PublicAction;
import com.fau.cm.entity.MedicalCallBlacklist;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 黑名单管理
 * @author liy
 * @datetime 2014年12月11日,下午6:04:56
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class MedicalBlackListAction extends PublicAction implements ModelDriven<MedicalCallBlacklist>{

	private static final long serialVersionUID = -404916054855881533L;
	
	private MedicalCallBlacklist callBlacklist = new MedicalCallBlacklist();
	
	/**
	 * @desc 进入黑名单管理页面
	 * @return String
	 * @author liy
	 * @datetime 2014年12月11日,下午6:07:13
	 */
	@Action(value = "call_blacklist_init",results = {@Result(location = "call_blacklist_init.jsp")})
	public String init() {
		return SUCCESS;
	}
	
	/**
	 * @desc 进入黑名单添加页面
	 * @return String
	 * @author liy
	 * @datetime 2014年12月11日,下午6:37:41
	 */
	@Action(value = "call_blacklist_add",results = {@Result(location = "call_blacklist_add.jsp")})
	public String add() {
		return SUCCESS;
	}
	
	/**
	 * @desc 进入黑名单修改页面
	 * @return String
	 * @author liy
	 * @datetime 2014年12月11日,下午8:40:44
	 */
	@Action(value = "call_blacklist_edit",results = {@Result(location = "call_blacklist_edit.jsp")})
	public String edit() {
		return SUCCESS;
	}
	
	/**
	 * @desc 分页查询黑名单
	 * @return null
	 * @author liy
	 * @datetime 2014年12月11日,下午6:16:41
	 */
	@Action(value = "call_blacklist_list")
	public String page(){
		HttpServletResponse response = ServletActionContext.getResponse();
		map = ServletActionContext.getContext().getParameters();
		pageBean = this.baseAllService.getTelService().findBlacklistByPage(this.callBlacklist, map);
		map.clear();
		map.put("total", pageBean.getTotalRow());
		map.put("data", pageBean.getResult());
		formatJSON(response, map);
		return null;
	}
	
	/**
	 * @desc 保存黑名单设置
	 * @return null
	 * @author liy
	 * @datetime 2014年12月11日,下午8:00:13
	 */
	@Action(value = "call_blacklist_save")
	public String save(){
		this.baseAllService.getTelService().insertBlacklist(this.callBlacklist);
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		this.map.put("success", true);
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 删除黑名单设置
	 * @return null
	 * @author liy
	 * @datetime 2014年12月11日,下午8:29:28
	 */
	@Action(value = "call_blacklist_del")
	public String delete(){
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		if(StringUtils.isNotBlank(callBlacklist.getId())) {
			this.baseAllService.getTelService().deleteBlacklist(this.callBlacklist);
			this.map.put("success", true);
		} else {
			this.map.put("success", false);
		}
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 修改黑名单设置
	 * @return null
	 * @author liy
	 * @datetime 2014年12月11日,下午8:38:12
	 */
	@Action(value = "call_blacklist_update")
	public String update(){
		this.baseAllService.getTelService().updateBlacklist(this.callBlacklist);
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		this.map.put("success", true);
		formatJSON(response, this.map);
		return null;
	}

	@Override
	public MedicalCallBlacklist getModel() {
		return callBlacklist;
	}

}
